package com.ruoyi.dev.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dev.domain.DevBatch;
import com.ruoyi.dev.service.IDevBatchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 批处理Controller
 * 
 * @author yepanpan
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/dev/batch")
public class DevBatchController extends BaseController
{
    @Autowired
    private IDevBatchService devBatchService;

    /**
     * 查询批处理列表
     */
    @PreAuthorize("@ss.hasPermi('dev:batch:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevBatch devBatch)
    {
        startPage();
        List<DevBatch> list = devBatchService.selectDevBatchList(devBatch);
        return getDataTable(list);
    }

    /**
     * 导出批处理列表
     */
    @PreAuthorize("@ss.hasPermi('dev:batch:export')")
    @Log(title = "批处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevBatch devBatch)
    {
        List<DevBatch> list = devBatchService.selectDevBatchList(devBatch);
        ExcelUtil<DevBatch> util = new ExcelUtil<DevBatch>(DevBatch.class);
        util.exportExcel(response, list, "批处理数据");
    }


    /**
     * 获取批处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dev:batch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(devBatchService.selectDevBatchById(id));
    }

    /**
     * 新增批处理
     */
    @PreAuthorize("@ss.hasPermi('dev:batch:add')")
    @Log(title = "批处理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DevBatch devBatch)
    {
        return toAjax(devBatchService.insertDevBatch(devBatch));
    }

    /**
     * 修改批处理
     */
    @PreAuthorize("@ss.hasPermi('dev:batch:edit')")
    @Log(title = "批处理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody DevBatch devBatch)
    {
        return toAjax(devBatchService.updateDevBatch(devBatch));
    }

    /**
     * 删除批处理
     */
    @PreAuthorize("@ss.hasPermi('dev:batch:remove')")
    @Log(title = "批处理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devBatchService.deleteDevBatchByIds(ids));
    }


    /**
     * 执行一次批处理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dev:batch:list')")
    @GetMapping(value = "/run/{id}")
    public AjaxResult runBatch(@PathVariable("id") Long id)
    {
        return success(devBatchService.runDevBatch(id));

    }
}
